<?php
class Product extends Eloquent {
	protected $table = 'product';
	const STATUS_INVISIBLE = 0;
	const STATUS_VISIBLE = 1;
	
	public function attribute()
	{
		return $this->hasOne('ProductAttribute');
	}
	public function images()
	{
		return $this->hasMany('ProductImage');
	}
	public function category()
	{
		return $this->belongsTo('ProductCategory','category_id');
	}
	public function comments()
	{
		return $this->hasMany('Evaluate','item_id');	
	}
	public function specs()
	{
		return $this->hasMany('ProductSpec');
	} 
    
    public static function getCompanyProducts()
    {
        return Product::where('category_id', '=', 1)->orderBy('sort', 'ASC')->get();
    }
    
    public static function getProducts()
    {
        return Product::where('status', self::STATUS_VISIBLE)->orderBy('sort', 'ASC')->get();
    }

    public static function getProduct($id)
    {
        return Product::where('id', '=', $id)->first();
    }

    public function getProductLife()
    {
        return ($this->id == 1)? 2:1;
    }
}
